package com.sky.mapper.admin;

import com.github.pagehelper.Page;
import com.sky.annotation.AutoFill;
import com.sky.dto.DishDTO;
import com.sky.dto.DishPageQueryDTO;
import com.sky.enumeration.OperationType;
import com.sky.pojo.Dish;
import com.sky.vo.DishVO;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.annotations.Param;

import java.util.List;

/**
 * 菜品数据层
 */
@Mapper
public interface DishMapper {

    /**
     * 根据分类id查询菜品数量
     * @param categoryId
     * @return
     */
    @Select("select count(id) from dish where category_id = #{categoryId}")
    Integer countByCategoryId(Long categoryId);

    /**
     * 新增菜品
     * @param dish
     */
    @AutoFill(OperationType.INSERT)
    @Options(useGeneratedKeys = true,keyProperty = "id")
    @Insert("insert into dish(name, category_id, price, image, description, status, create_time, update_time," +
            " create_user, update_user, make_time) VALUES (#{name},#{categoryId},#{price},#{image},#{description}," +
            "#{status},#{createTime},#{updateTime},#{createUser},#{updateUser},#{makeTime})")
    void insert(Dish dish);

    /**
     * 菜品分页
     * @param dishPageQueryDTO
     * @return
     */
    Page<DishVO> list(DishPageQueryDTO dishPageQueryDTO);

    /**
     * 删除菜品
     * @param ids
     */
    void delete(List<Long> ids);


    /**
     * 查询菜品状态
     * @param ids
     */
    Integer queryStatus(@Param("ids") List<Long> ids, @Param("status") Integer status);

    /**
     * 根据id查找菜品和口味
     * @param id
     * @return
     */
    DishVO seleteById(Long id);

    /**
     * 修改菜品
     * @param dish
     */
    @AutoFill(OperationType.UPDATE)
    void update(Dish dish);

    /**
     * 根据分类id查菜品
     * @param categoryId
     * @return
     */
    @Select("select id, name, category_id, price, image, description, status, create_time, update_time, create_user, update_user, make_time from dish where category_id =#{categoryId}")
    List<Dish> seleteByCategoryId(Long categoryId);

    /**
     * 修改菜品状态
     * @param id
     */
    @Update("update dish set status = #{status} where id = #{id}")
    void updateDishStatus(Integer status ,Long id);


    /**
     * 根据分类id查询菜品
     * @param dish
     * @return
     */
    @Select("select id, name, category_id, price, image, description, status, create_time, update_time, create_user, update_user, make_time from dish where category_id = #{categoryId} and status = #{status}")
    List<Dish> listByDish(Dish dish);
}
